package com.leoandroid.tool.toolsbox.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.RecyclerView
import com.leoandroid.tool.toolsbox.bean.NBAInfoBean
import com.leoandroid.tool.toolsbox.largeread.R
import com.leoandroid.tool.toolsbox.largeread.databinding.ItemNbaLayoutBinding

class NBAItemAdapter(val context: Context,val daraList:ArrayList<NBAInfoBean.NBAListInfo>):RecyclerView.Adapter<NBAItemAdapter.Holder>() {
    inner class Holder(itemView: View) :RecyclerView.ViewHolder(itemView){
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Holder {
        val inflate = DataBindingUtil.inflate<ItemNbaLayoutBinding>(
            LayoutInflater.from(context),
            R.layout.item_nba_layout,
            parent,
            false
        )
        return Holder(inflate.root)
    }

    override fun onBindViewHolder(holder: Holder, position: Int) {
        val dataBind:ItemNbaLayoutBinding? = DataBindingUtil.getBinding<ItemNbaLayoutBinding>(holder.itemView)

        dataBind?.apply {
            daraList[position].apply {
                timeTitle.text = time_start
                itemTeam1.text = team1
                itemTeam2.text = team2
                itemTeam1Score.text = team1_score
                itemTeam2Score.text = team2_score
//                比赛状态, 1未开赛 2进行中 3完赛 4延期
                when(status){
                    "1"->{
                        itemMatchStatus.text = "未开赛"
                    }
                    "2"->{
                        itemMatchStatus.text = "进行中"
                    }
                    "3"->{
                        itemMatchStatus.text = "完赛"
                    }
                    "4"->{
                        itemMatchStatus.text = "延期"
                    }
                }
            }
        }
    }

    override fun getItemCount(): Int = daraList.size
}